const store = require("./index");

console.log("init: ", store.getState());

// 定义一个action
const addAction = {
  type: "ADD",
  payload: {
    id: "002",
    name: "lisi",
    age: 19,
    address: "上海市",
  },
};

// 定义一个action
const deleteAction = {
  type: "DELETE",
  payload: "001",
};

// 订阅store的变化
const unsubscribe = store.subscribe(() => {
  console.log("update: ", store.getState());
});

setTimeout(() => {
  // 取消订阅
  unsubscribe();
}, 3000);

// 派发action
store.dispatch(addAction);
store.dispatch(deleteAction);
